package com.credit.jumu.calculator.utils;

import android.content.Context;
import android.util.Log;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by Administrator on 2017/11/28/028.
 */

public class AddressUtil {
	//读取assets中的文件
	public static String readFromAssets(Context context) {
		try {
			InputStream is = context.getAssets().open("adds.json");//此处为要加载的json文件名称
			String text = readTextFromSDcard(is);
			return text;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Log.d("readFromAssets", e.toString());
			return "";
		}
	}

	//将传入的is一行一行解析读取出来出来
	private static String readTextFromSDcard(InputStream is) throws Exception {
		InputStreamReader reader = new InputStreamReader(is, "UTF-8");
		BufferedReader bufferedReader = new BufferedReader(reader);
		StringBuffer buffer = new StringBuffer("");
		String str;
		while ((str = bufferedReader.readLine()) != null) {
			buffer.append(str);
			//buffer.append("\n");
		}
		return buffer.toString();//把读取的数据返回
	}
}
